<template>
	<view class="my-content page">
		<view style="background:  #efefef;padding: 20rpx 0 20rpx 0;">
			<view v-for="(i, index) in list" :key="index" class="bidding_news">
				<view class="bidding_card">
					<view class="bidding_betwn">
						<view class="bidding_user">
							<view class="name">{{ goods(type, i.goods_type || i.release_type, i.human_type) }}</view>
							<view class="del">
								<u-icon name="trash" color="orange" size="60" @click="del(i.id,i)"></u-icon>
								<!-- <u-modal :show-title="false" @confirm="confirm" :show-cancel-button="true"
									v-model="show" :content="content" :cancel-text="$t('取消')"
									:confirm-text="$t('确认')"></u-modal> -->
							</view>
						</view>
					</view>
					<!--信息展示-->
					<!-- 货物 -->
					<view v-if="type == 'goods'" class="biddin_synopsis">
						<view class="bidding_synopsis_sel">
							<text class="text1">{{ $t('货物名称') }}：</text>
							<text>{{ i[$t('item.name')] }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text class="text1">{{ $t('数量') }}：</text>
							<text>{{ i[$t('item.goods_num')] }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text class="text1">{{ $t('重量') }}：</text>
							<text>{{ i[$t('item.goods_weight')] + $t('kg') || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text class="text1">{{ $t('体积') }}：</text>
							<text>{{ i[$t('item.goods_volume')] + $t('m³') || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text class="text1">{{ $t('出发地') }}：</text>
							<text>{{ i.departurecitys[$t('item.city.mergename')] }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text class="text1">{{ $t('到达地') }}：</text>
							<text>{{ i.reachcitys[$t('item.city.mergename')] }}</text>
						</view>
					</view>
					<!-- 运输 -->
					<view v-if="type == 'transport'" class="biddin_synopsis">
						<view class="bidding_synopsis_sel" v-if="i.release_type === '1'">
							<text>{{ $t('车型') }}：</text>
							<text>{{ i.category[$t('item.name')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel" v-if="i.release_type === '2'">
							<text>{{ $t('所需车型') }}：</text>
							<text>{{ i.category[$t('item.name')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel" v-if="i.release_type === '3'">
							<text>{{ $t('货物名称') }}：</text>
							<text>{{ i[$t('item.goods_name')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel" v-if="i.release_type === '1'">
							<text>{{ $t('车辆尺寸') }}：</text>
							<text>
								{{
									$t('长') + i[$t('item.car_l')] + 'm，' + $t('宽') + i[$t('item.car_w')] + 'm，' + $t('高') +
									i[$t('item.car_h')] + 'm' || ''
								}}
							</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('出发地') }}：</text>
							<text>{{ i.departurecitys[$t('item.city.mergename')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('到达地') }}：</text>
							<text>{{ i.reachcitys[$t('item.city.mergename')] || '' }}</text>
						</view>
					</view>

					<!-- 跨境货代 -->
					<view v-if="type == 'crossborder'" class="biddin_synopsis">
						<view class="bidding_synopsis_sel">
							<text>{{ $t('运输方式') }}：</text>
							<text>{{ mapMode($t(i.mode)) }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('通关口岸') }}：</text>
							<text>{{ i.portcitys[$t('item.city.mergename')] }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('出发地国家') }}：</text>
<!-- 							<text>{{ i.departurecitys[$t('item.city.mergename')] || '' }}</text> -->
							<text v-if="i.departure_country==0">{{$t('中国')}}</text>
							<text v-if="i.departure_country==1">{{$t('俄罗斯')}}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('到达地国家') }}：</text>
							<text v-if="i.reach_country==0">{{$t('中国')}}</text>
							<text v-if="i.reach_country==1">{{$t('俄罗斯')}}</text>
							
<!-- 							<text>{{ i.reachcitys[$t('item.city.mergename')] || '' }}</text> -->
						</view>
					</view>

					<!-- 专业代办 -->
					<view v-if="type == 'professional'" class="biddin_synopsis">
						<view class="bidding_synopsis_sel">
							<text>{{ $t('个人名称') }}：</text>
							<text>{{ i[$t('item.person_name')] || '' }}</text>
						</view>
						<view v-if="i[$t('item.scope_category')]" class="bidding_synopsis_sel">
							<text>{{ $t('经营范围') }}：</text>
							<text>{{ i[$t('item.scope_category')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('专业技能') }}：</text>
							<text>{{ i[$t('item.skill')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('所在城市') }}：</text>
							<text>{{ i.personcitys[$t("item.city.mergename")] || '' }}</text>
						</view>
					</view>

					<!-- 生活广告 -->
					<view v-if="type == 'lifead'" class="biddin_synopsis">
						<view class="bidding_synopsis_sel">
							<text>{{ $t('广告标题') }}：</text>
							<text>{{ i[$t('item.title')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('广告内容') }}：</text>
							<text>{{ i[$t('item.content')] }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('所在城市') }}：</text>
							<text>{{ i.lifeadcitys[$t('item.city.mergename')] || '' }}</text>
						</view>
					</view>

					<!-- 曝光台 -->
					<view v-if="type == 'exposure'" class="biddin_synopsis">
						<view class="bidding_synopsis_sel">
							<text>{{ $t('曝光标题') }}：</text>
							<text>{{ i[$t('item.title')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('曝光内容') }}：</text>
							<text>{{ i[$t('item.content')] || '' }}</text>
						</view>
						<view class="bidding_synopsis_sel">
							<text>{{ $t('所在城市') }}：</text>
							<text>{{ i.exposurecitys[$t('item.city.mergename')] || '' }}</text>
						</view>
					</view>
					<!--商品图片展示区(控制是否显示）-->
					<view class="bidding_image" v-if="type == 'goods'">
						<image v-for="(ele, index) in i.buy_images" :key="index" :src="IMAGE_URL + ele"></image>
					</view>
					<view class="bidding_image" v-else>
						<image v-for="(ele, index) in i.images" :key="index" :src="IMAGE_URL + ele"></image>
					</view>
					<view class="bidding_address">
						<view class="bidding_ares">
							<view class="bidding_ares1" v-if="false">
								<image :src='serverImageUrl("/static/images/index/dizhi.png")'></image>
								<view v-if="type == 'professional'"
									style="margin-left: 10rpx;max-width: 340rpx;word-wrap: break-word;">
									{{ i.personcitys[$t("item.city.mergename")] || '' }}
								</view>
								<view v-else-if="type == 'lifead'"
									style="margin-left: 10rpx;max-width: 340rpx;word-wrap: break-word;">
									{{ i.lifeadcitys[$t('item.city.mergename')] }}
								</view>
								<view v-else-if="type == 'exposure'"
									style="margin-left: 10rpx;max-width: 340rpx;word-wrap: break-word;">
									{{ i.exposurecitys[$t('item.city.mergename')] }}
								</view>
								<view v-else style="margin-left: 10rpx;max-width: 340rpx;word-wrap: break-word;">
									{{ i.departurecitys[$t('item.city.mergename')] }}
								</view>
							</view>
							<view class="bidding_time">
								<text style="line-height: 50rpx;">{{ time("S", i.updatetime) }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-empty v-if="list.length === 0" mode="list" margin-top="200"></u-empty>
		</view>
	</view>
</template>

<script>
	import {
		IMAGE_URL
	} from '@/config/app';
	import {
		time
	} from "@/common/public";
	export default {

		data() {
			return {
				IMAGE_URL,
				list: [],
				content: this.$t('确认删除么') + '?',
				show: false,
				type: null,
				id: 0,
				category: null,
				orderStatus: null
			};
		},
		onLoad(option) {
			
			console.log(option)
			this.$u.api.user.getMyRelease({
				type: option.type,
				release_type: option.name
			}).then(res => {
				this.list = res
				console.log(this.list);
			})
			this.category = option.type
			this.type = option.name
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t("我的发布")
			})
		},
		methods: {
			time,
			del(id, e) {
				this.id = id
				this.show = true
				this.orderStatus = e.order_status;
				// order_status '状态:0=待参与,1=已参与,2=进行中(已合作),3=已取消,4=申请售后,5=售后已完成,6=发布方确认收货(进行中),7=已评价,8=同意延期付款(已完成),9=未付款(不同意延期),10=已完成'
				if (this.orderStatus == '0' || this.orderStatus == '3' || this.orderStatus == '5' || this.category === '1') {
					uni.showModal({ //提醒用户更新
					  title: this.$t('我的发布'),
					  content: this.$t("确认删除吗"),
					  confirmText: this.$t('确认'), // 修改确认按钮文字
					  cancelText: this.$t('取消'),  
					  success: (res) => {
						  if (res.confirm) {
							 this.$u.api.user.delMyRelease({
							 	type: this.type,
							 	id: this.id
							 }).then(res => {
							 	this.$u.toast(this.$t('删除成功'))
							 	this.$u.api.user.getMyRelease({
							 		type: this.category,
							 		release_type: this.type
							 	}).then(res => {
							 		this.list = res
							 	})
							 	// console.log(res);
							 })
							  // 用户点击了确定，执行相应的逻辑
						  } else if (res.cancel) {
							  // 用户点击了取消，执行相应的逻辑
						  }
					  }
					})
				} else {
					this.$u.toast(this.$t('不可删除'))
				}
			},

			// confirm() {
			// order_status '状态:0=待参与,1=已参与,2=进行中(已合作),3=已取消,4=申请售后,5=售后已完成,6=发布方确认收货(进行中),7=已评价,8=同意延期付款(已完成),9=未付款(不同意延期),10=已完成'
			// 	if (this.orderStatus == '0' || this.orderStatus == '3' || this.orderStatus == '5' || this.category === '1') {
			// 		this.$u.api.user.delMyRelease({
			// 			type: this.type,
			// 			id: this.id
			// 		}).then(res => {
			// 			this.$u.toast(this.$t('删除成功'))
			// 			this.$u.api.user.getMyRelease({
			// 				type: this.category,
			// 				release_type: this.type
			// 			}).then(res => {
			// 				this.list = res
			// 			})
			// 			// console.log(res);
			// 		})
			// 	} else {
			// 		this.$u.toast(this.$t('不可删除'))
			// 	}
			// },

			mapMode(mode) {
				let modeArr = mode.split(',')
				let ret = ''
				for (let i in modeArr) {
					if (i > 0) {
						ret += '，' + this.$t(modeArr[i])
					} else {
						ret += this.$t(modeArr[i])
					}
				}
				return ret
			},

			storeImages() {
				return (sum, images) => {
					if (!Array.isArray(images)) return images
					return images.length > sum ? images.splice(sum) : images
				}
			},

			goods(i, name, value) {
				if (i == 'goods') {
					switch (name) {
						case '1':
							return this.$t('中国货物')
						case '2':
							return this.$t('俄罗斯货物')
						case '3':
							return this.$t('在俄中国货物')
						case '4':
							return this.$t('在中俄罗斯货物')
						default:
							break;
					}
					return
				}
				if (i == 'transport') {
					switch (name) {
						case '1':
							return this.$t('有车求货')
						case '2':
							return this.$t('有货求车')
						case '3':
							if (value == 1) {
								return this.$t('人力捎货') + '-' + this.$t('货源信息')
							} else {
								return this.$t('人力捎货') + '-' + this.$t('我要带货')
							}
						default:
							break;
					}
					return
				}
				const data = {
					crossborder: this.$t('跨境货代'),
					professional: this.$t('专业代办'),
					lifead: this.$t('生活广告'),
					exposure: this.$t('曝光台'),
				}
				// console.log(data[i]);
				return data[i]
			},
		}
	}
</script>

<style lang="scss" scoped>
	@keyframes changeImg {
		from {
			left: -100%;
		}

		100% {
			left: 150%;
		}
	}

	.page {
		background: #efefef;

		.bidding_news {
			display: flex;
			justify-content: center;
			margin-bottom: 31.4rpx;

			.bidding_card {
				width: 692rpx;
				background: $my-bgColorFFFFFF;
				box-shadow: 3rpx 7rpx 3rpx 0rpx rgba(234, 234, 234, 0.5);
				border-radius: 14rpx;
				overflow: hidden;

				.bidding_user {
					min-height: 80rpx;
					display: flex;
					// flex-direction: row;
					// align-items: center;
					align-items: flex-start;
					justify-content: space-between;
					margin-bottom: 10rpx;

					// align-items: flex-start;
					// overflow: hidden;
					// padding-bottom: 20rpx;
					// flex: 1;
					//头像大小
					.bidding_user_image {
						border: 1rpx solid orange;
						box-sizing: border-box;
					}

					//用户图标
					.bidding_user_icon {
						padding-left: $my-padding-10;
						height: 35rpx;
						width: 35rpx;
					}
				}

				//商品的简介
				.biddin_synopsis {
					display: flex;
					flex-direction: column;
					justify-content: flex-start;
					padding: 0 $my-padding-20 $my-padding-20 $my-padding-20;

					.bidding_synopsis_sel {
						margin-top: 34.88rpx;
						padding-left: 26.16rpx;
						font-size: $my-font-size21;
						line-height: 40rpx;

						text {
							&:first-child {
								color: #aaa;
							}

							&:last-child {
								color: #333;
								font-size: 32rpx;
							}
						}
					}
				}

				//商品图片展示区
				.bidding_image {
					padding: $my-padding-20 0 0 $my-padding-20;

					image {
						width: 229.07rpx;
						height: 225.58rpx;
						margin: 0 30rpx 30rpx 0;
						border-radius: 20rpx;
						box-shadow: 0px 0px 8px 0px #ababab;
					}
				}

				//地址信息
				.bidding_address {
					padding: 13.6rpx $my-padding-20 10rpx $my-padding-20;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					font-size: $my-font-size21;
					font-weight: 400;
					color: #888888;
					line-height: 30rpx;

					.bidding_ares {
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: flex-start;

						.bidding_time {
							width: 100%;
							text-align: right;
						}

						.bidding_ares1 {
							display: flex;
							justify-content: flex-start;

							image {
								width: 24.42rpx;
								height: 31.4rpx;
							}
						}
					}
				}
			}
		}
	}

	.del {
		// align-items: flex-end;
		height: 100%;
		margin-right: 10rpx;
		// display: flex;
		margin-top: 10rpx;
	}

	.name {
		background: linear-gradient(132deg, #FBAA52 0%, #E96444 100%);
		color: white;
		float: left;
		max-width: 400rpx;
		// line-height: 60rpx;
		padding: 15rpx 20rpx 10rpx 20rpx;
		position: relative;

		&::after {
			position: absolute;
			animation: changeImg 3s ease 0s;
			top: 0;
			width: 30%;
			height: 100%;
			content: "";
			background: linear-gradient(to right, rgba(255, 255, 255, 0) 0, rgba(255, 255, 255, .4) 50%, rgba(255, 255, 255, 0) 100%);
			transform: skewX(-45deg);
			animation-iteration-count: infinite;
		}
	}
</style>